<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>冒泡事件</title>

    <!-- 小球随鼠标移动，但不进入box2区域 -->
     
    <style>
        #box1 {
            width: 50px;
            height: 50px;
            border-radius: 50%;
            background-color: #bca;
            position: absolute;
        }

        #box2 {
            width: 100px;
            height: 100px;
            background-color: #bce;
        }
    </style>
</head>
<body>
    <div id="box1"></div>
    <div id="box2"></div>
    <script>
        const box1 = document.getElementById("box1");
        const box2 = document.getElementById("box2");
        //由于事件冒泡属性，我们只需绑定一个事件，不用在每个位置都绑定事件
        document.addEventListener("mousemove",(event)=>{
            box1.style.left = event.x + "px";
            box1.style.top = event.y + "px";
        })

        //box2取消冒泡，则小球不进入box2区域
        box2.addEventListener("mousemove",(event)=>{
        event.stopPropagation();
        })
    </script>
</body>
</html>